package org.codeart.chainrespon.example03;

import com.alibaba.fastjson.JSON;
import org.codeart.chainrespon.example02.AuthService;
import org.codeart.chainrespon.pojo.AuthInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Client {

    private static final Logger logger = LoggerFactory.getLogger(Client.class);

    public static void main(String[] args) throws ParseException {
        AuthLink authLink3 = new Level3AuthLink("1000013", "高斯");
        AuthLink authLink2 = new Level2AuthLink("1000012", "欧拉");
        AuthLink authLink1 = new Level1AuthLink("1000011", "伯努利");
        authLink3.appendNext(authLink2);
        authLink2.appendNext(authLink1);

        SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = dateFormatter.parse("2024-05-01 00:00:00");

        AuthInfo authInfo;
        authInfo = authLink3.doAuth("洛必达", "0434310347343134", date);
        logger.info("测试结果: {}", JSON.toJSONString(authInfo));

        // 三级审批
        AuthService.auth("1000013", "0434310347343134");
        authInfo = authLink3.doAuth("洛必达", "0434310347343134", date);
        logger.info("测试结果: {}", JSON.toJSONString(authInfo));

        // 二级审批
        AuthService.auth("1000012", "0434310347343134");
        authInfo = authLink3.doAuth("洛必达", "0434310347343134", date);
        logger.info("测试结果: {}", JSON.toJSONString(authInfo));

        // 一级审批
        AuthService.auth("1000011", "0434310347343134");
        authInfo = authLink3.doAuth("洛必达", "0434310347343134", date);
        logger.info("测试结果: {}", JSON.toJSONString(authInfo));
    }

}
